import User from "@/views/system/user/user.vue";
import {PageParam} from "@/components/pageTable/types/type.ts";
import user from "@/views/system/user/user.vue";
import {Result} from "@/common/comTypes/commonTypes.ts";

export interface UserInfo {
    id: string,
    username: string,
    nickname: string,
    gender: number,
    birthday: string,
    status: 0 | 1,
}

let userList = [{
    id: "001",
    username: "litchiUser001",
    nickname: "荔枝的ikun",
    gender: 1,
    birthday: "2020-01-01",
    status: 1,
},
    {
        id: "002",
        username: "litchiUser002",
        nickname: "香精煎鱼",
        gender: 0,
        birthday: "2020-01-01",
        status: 0,
    },
    {
        id: "003",
        username: "litchiUser003",
        nickname: "香翅捞饭",
        gender: 0,
        birthday: "2020-01-01",
        status: 1,
    },
    {
        id: "004",
        username: "litchiUser004",
        nickname: "香精橘子",
        gender: 1,
        birthday: "2020-01-01",
        status: 1,
    },
    {
        id: "005",
        username: "litchiUser005",
        nickname: "你干嘛哎哟~~",
        gender: 1,
        birthday: "2020-01-01",
        status: 1,
    },
    {
        id: "006",
        username: "litchiUser006",
        nickname: "我家鸽鸽",
        gender: 1,
        birthday: "2020-01-01",
        status: 1,
    },
    {
        id: "007",
        username: "litchiUser007",
        nickname: "梅素汁",
        gender: 1,
        birthday: "2020-01-01",
        status: 1,
    },
    {
        id: "008",
        username: "litchiUser008",
        nickname: "只因你太美 o baby",
        gender: 1,
        birthday: "2020-01-01",
        status: 1,
    },
    {
        id: "009",
        username: "litchiUser009",
        nickname: "灰勒塔的钱兔",
        gender: 1,
        birthday: "2020-01-01",
        status: 0,
    },
    {
        id: "010",
        username: "litchiUser010",
        nickname: "灰勒塔的医生",
        gender: 0,
        birthday: "2020-01-01",
        status: 1,
    },
    {
        id: "011",
        username: "litchiUser011",
        nickname: "灰勒塔",
        gender: 1,
        birthday: "2020-01-01",
        status: 1,
    },
] as UserInfo[]

export function getPageData(pageParam: PageParam<any>): Promise<Result<any>> {
    console.log(pageParam)
    let current = pageParam.current
    let size = pageParam.size

    return new Promise<Result<any>>((resolve, reject) => {
        setTimeout(() => {

            const resultList1 = userList.filter(item => {
                if (pageParam.param?.nickname != '') {
                    if (item.nickname.includes(pageParam.param?.nickname)) {
                        return item
                    }

                } else {
                    return item
                }
            })
            const resultList2 = resultList1.filter(item => {
                if (pageParam.param?.status!==''&&pageParam.param?.status!==undefined) {
                    if (item.status === pageParam.param?.status) {
                        return item
                    }
                } else {
                    return item
                }
            })


            const total = resultList2.length
            const start = (current - 1) * size
            const end = start > total ? total : start + size
            const resultList = resultList2.filter((item, index) => {
                if (index >= start && index < end) {
                    return item
                }
            })
            const result = new Result<any>();
            result.buildData({
                list: resultList,
                total: total
            })
            resolve(result)
        }, 800);
    });
}

export function removeById(id: string): Promise<Result<string>> {
    return new Promise<Result<string>>((resolve, reject) => {
        setTimeout(() => {
            userList = userList.filter(item => {
                if (item.id != id) {
                    return item
                }
            })
            const result = new Result<string>()
            resolve(result)
        }, 700)
    })
}